import requests

import Function.People as People
from Function import Database, Data


def getChaoxingDiscussPeople():

    baseUrl = "https://groupweb.chaoxing.com/pc/invitation/getReplyList?bbsid=c4329637bea70ef6331c9bf1080c5ddb&uuid=60f4bed0f22f4b70871ff3932e24ac66&tag=&order=2"
    lastValue = ''
    getPeopleList = []
    # 头部信息
    headers = {
        "cookie": "createSiteSource=num3; wfwEnc=A2CDBA44D1D2C5AF0D1CD53BD025C183; tl=1; lv=2; fid=1842; _uid=199462244; uf=b2d2c93beefa90dc7d0f9867706e3a6eec7bb309ffd90225a6bb53f69841698fda0b5f1484f3765e1f390e4e67a879ec913b662843f1f4ad6d92e371d7fdf644d490c7da6f959ca6fd68be96b6183b1ad6cc853b47e9a6a03f34d7e5dc61d936bd10c1a2221d4b3a; _d=1709043429571; UID=199462244; vc=D40C4B930F1FDBC287BED3E0A86970EC; vc2=32094B1BFAE3B660B942D2824CF5FD55; vc3=dJOQT%2F0SlpMnvi8kSCui8vP%2F7wIBg2R9tPGQbzukrhYnPmTGksPK8g5ZjHPdmd9tkL8s7POO9tjWYZ2jw2F%2BBvqeWEnAzHJPfXMC2BWD2jROThoBZ8wEqvIUZBTyYhbC%2BWh%2Bc0GZx2SJ5ZRjp0IoMRoChq0klctJHb8%2FDyiuH34%3D10f9c3569e56cdc03777687f8c17161f; cx_p_token=e45dc8d0bb29553ea08870f70e2bb548; p_auth_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxOTk0NjIyNDQiLCJsb2dpblRpbWUiOjE3MDkwNDM0Mjk1NzMsImV4cCI6MTcwOTY0ODIyOX0.IyGsiJ67ahwwqaK7gwd12jbG67Sf3lFcoeV69x2cpYU; xxtenc=133db1f3b96fe3ef7b8d44368fd99565; DSSTASH_LOG=C_38-UN_100-US_199462244-T_1709043429573; _industry=5; 241139678cpi=206980800; 241139678ut=s; source=""; spaceFid=1842; spaceRoleId=3; 241139678t=1709110600564; 241139678enc=0fe9327fe58e6b3f2d4c31b72b36306e; JSESSIONID=7F91DC2F60C79151E066AD524E635E12.GroupTopic_WEB; route=1bb6f7ae0232fddbe92682ba64bbd02f",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
    }

    while True:
        res = requests.get(baseUrl + "&lastValue=" + lastValue, headers=headers)
        data = res.json()
        lastValue = str(data.get("poff").get("lastValue"))
        if len(data.get("datas")) != 0:
            for item in data.get("datas"):
                getPeopleList.append(item.get("creater_name"))
        else:
            break
    return getPeopleList


# 定义类
database_address = "Database/Data.db"

# 获取超星讨论页发言的人
peopleList = getChaoxingDiscussPeople()
# 获取班级学生的姓名
student_name_list = Database.read_column_data_to_list(database_address, "students", "name")
# 计数
countResult = Data.list_count(student_name_list, peopleList)
# 获取完成和未完成任务的学生的列表，并合成一个字典
allStudentsDic = People.getAllStudentsDic(countResult, student_name_list)
# 获取名字列表
undoNameList = allStudentsDic.get('undo')
doneNameList = allStudentsDic.get('done')
# 获取学号列表
undoIDList = People.nameToID(undoNameList)
doneIDList = People.nameToID(doneNameList)
# 输出
print(f"未完成({len(undoIDList)}人)：{' '.join(undoIDList)}\n")
print(f"已完成({len(doneIDList)}人)：{' '.join(doneIDList)}")
